﻿namespace SqliteDAL.DAL
{
    public class DbContextFactory
    {
        static MyContext dbContext = null;
        static object lockobj = new object();  
        /// <summary>
        /// 保证EF上下文在线程内唯一（也就是一次请求内）
        /// </summary>
        /// <returns></returns>
        public static MyContext CreateDbContext()
        {
            lock (lockobj)
            {
                if (dbContext == null)
                {
                    dbContext = new MyContext();
                }
            }
            return dbContext;
        }
    }
}
